package handler

import (
	"github.com/gin-gonic/gin"
	"tvmanager/model"
)

func AddTV(c *gin.Context) {
	title := c.PostForm("title")
	style := c.PostForm("style")
	actor := c.PostForm("actor")
	desc := c.PostForm("desc")
	if title == "" || style == "" || actor == "" || desc == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}
	var t model.TV
	t.Title = title
	t.Style = style
	t.Actor = actor
	t.Desc = desc
	err := model.DB.Create(&t).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
func List(c *gin.Context) {

	var list []model.TV
	err := model.DB.First(&list).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 400,
			"msg":  "查找失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查找成功",
		"Data": list,
	})
	return
}
